package uriel.frankel.model;

public class IncomeTax {
	
	private static final int VALUE_OF_1_POINT_2013 = 218;
	private final double TOP_PENSION_ZIKUI = 8600*7*PERCENT*35*PERCENT;
	private static final double PERCENT = 0.01;	
	public double mPoints = 2.25;
public double[][] steps = {
			
			{10,5280,0},
			{14,9010,0},
			{21,14000,0},
			{31,20000,0},
			{34,41830,0},
			{48,67630,0},
			{50,0,0}
			};
private double mPension;

public double setSumedIrs(int index){
	double sum = 0;
	
	sum+= (double)(steps[0][0]*(steps[0][1]))*PERCENT;
	for (int j = 1; j <= index; j++) {
		
		
			sum+= (double)(steps[j][0]*(steps[j][1]-steps[j-1][1]))*PERCENT;
		
	}
	return sum;
}
	



	public IncomeTax() {
		for (int i = 0; i < steps.length; i++) {
			steps[i][2] = setSumedIrs(i);
		}
	}
	
	public IncomeTax(double taxesSalary,double points,double pension) {
		super();
		mPoints = points;
		mPension = pension;
		mTaxesSalary = taxesSalary;
	}

	private double mTaxesSalary;

	public double getIncomeTax() {
		double taxPercent;
		double IrsToPay;
		// �?דרגות �?ס וכ�? השיט
		if ((mTaxesSalary) < steps[0][1]) {
			taxPercent = steps[0][0]/100;
			IrsToPay = (mTaxesSalary) * taxPercent ;
		} else if ((mTaxesSalary) < steps[1][1]) {
			taxPercent = steps[1][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[0][1]) * taxPercent + setSumedIrs(0);
		} else if ((mTaxesSalary) < steps[2][1]) {
			taxPercent = steps[2][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[1][1]) * taxPercent + setSumedIrs(1);
		} else if ((mTaxesSalary) < steps[3][1]) {
			taxPercent = steps[3][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[2][1]) * taxPercent + setSumedIrs(2);
		} else if ((mTaxesSalary) < steps[4][1]) {
			taxPercent = steps[4][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[3][1]) * taxPercent + setSumedIrs(3);
		} else if((mTaxesSalary) < steps[5][1]) {
			taxPercent = steps[5][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[4][1]) * taxPercent + setSumedIrs(4);
		}else{
			taxPercent = steps[6][0]/100;
			IrsToPay = ((mTaxesSalary) - steps[5][1]) * taxPercent + setSumedIrs(5);
		}


		
		//והכי חשוב זה נקודות זיכוי
		IrsToPay = IrsToPay - mPoints * VALUE_OF_1_POINT_2013;

		//עובד שהפריש �?שכרו סכו�?י�? �?צור�? חסכו�? �?פנסיה זכ�?י �?זיכוי �?�?ס הכנסה בשיעור 35% �?תו�? הסכו�?י�? שהפריש
		//הסכו�? ה�?קסי�?�?�?י ש�?זכה בהטבה הו�? 7,140 ש"ח �?שנה, ובכ�? �?קרה �?�? יותר �?-5% �?השכר
		double zikui = 0.35*mPension;
		if(zikui>TOP_PENSION_ZIKUI){
			zikui = TOP_PENSION_ZIKUI;
		}
		IrsToPay -=zikui;

		if (IrsToPay < 0)
			IrsToPay = 0;
		return IrsToPay;
	}
	
}
